import facade
from xjlibrary.our_file_dir import BaseDir

curpath = BaseDir.get_file_dir_absolute(__file__)
TopPath = BaseDir.get_upper_dir(curpath, -2)
dirPath = BaseDir.get_new_path(TopPath, "download", "gzlg_botu", "download", "list")
configfile = BaseDir.get_new_path(curpath, "db.ini")


class UpArticle(object):
    def __init__(self):
        self.logger = facade.get_streamlogger()
        self.mysqlutils = facade.MysqlUtiles(configfile, "db", logger=self.logger)

    def select(self):
        sql = "select rawid from article_copy1 where coverstat=0 limit 10000"
        rows = self.mysqlutils.SelectFromDB(sql)
        print(len(rows))
        Listvalue = []
        Listvalue2 = []
        for row in rows:
            Listvalue.append(row[0])
            value = row[0].strip()
            Listvalue2.append((value))
        sql = "insert ignore into article (rawid) values (%s)"
        self.mysqlutils.ExeSqlMany(sql, Listvalue2)
        sql = "update article_copy1 set coverstat=1 where rawid in {}".format(tuple(Listvalue))
        self.mysqlutils.ExeSqlToDB(sql)


if __name__ == "__main__":
    up = UpArticle()
    while True:
        up.select()
